REST Architectural Style

Table of Contents

Introduction to my notes

REST is an architectural style that Roy Fielding introduced in his thesis Architectural Styles and the Design of Network-based Software Architectures. I found this paper interesting for a couple of reasons:

  • Most of the paper is not actually about REST. It is about software architecture, and it introduces a framework for selecting the correct architectural style for your network based system. This framework is a methodological approach for designing systems and is a useful addition to your tool belt.
  • It also contains an interesting history lesson about the early www and its requirements, mistakes, and learning from those mistakes in order to architect the modern web.
  • It has a lot less to do with APIs than I thought.

These are a collection of my notes and thoughts while I was studying the topic. It's not meant to be a comprehensive review of the topic (although I do hope to add more content around some parts I handwaved over), but an aid in building some intuition. Hopefully they will help digest what REST is, and inspire you to read Roy Fielding's dissertation.

What is REST?

I'll try to describe REST a few different ways. I'll start off simple and then try to describe it by introducing some vocaubulary Fielding uses in his dissertation.

REST is the architecture of the world-wide-web

In the early 90's, it became clear that the WWW would become extremely popular. Unfortunately the early web was not prepared for that kind of rapid growth and the architecture had to be revisited. But there was a problem… a description of the architecture didn't exist. The WWW was designed by informal notes, a couple of papers, and discussion on mailing lists. To improve on the architecture, the architecture must first be extrapolated form the early web. REST is this extrapolated archictecture, along with improvements needed to support the modern web.

REST is the result of building an architecture that has the following properties (summarized at a high level by me):

  • Evolvability
  • Extendability
  • Scalability
  • Simplicity

REST is an Architectural Style

  • An architectural style is a set of architectural constraints.
  • Architectural constraints bring about a set of properties on your system.
    • You already know one example of a contraint: client-server. Properties that the client-server constraint induces on your system are evolvability and scalability.
  • The set of architectural constraints that describe REST are:
    • Client Server
    • Stateless
    • Cache
    • Uniform Interface
    • Layered System
    • Code-on-demand (optional)

REST focuses on scalability and evolvability through a uniform interface.

  • The uniform interface constraint distinguishes REST from other network based architectural styles.
  • By having components communicate through a uniform interface, implementations become decoupled from the services that they provide.
  • For the WWW, the uniform interface is implemented through resources, resource representations, self-descriptive messages, and hypermedia.

Practical Benefits of REST

  • If you are part of a software system that involves multiple organizations (this can also be multiple organizations within a single company), it is very difficult to decide how to pass data between the different components of the system. Especially so when those systems cross organizational boundaries. The uniform interface allows you to standardize on messages between the components of your system rather than the data.

    For example, consider HTML forms. HTML forms are hypermedia that describes (in the message) what data should be sent between two systems, and how that data should be sent. As long as the systems implement the contract described through the message, the service is decoupled from the implementation of the service and decoupled from details such as internal data models used throughout the system.

  • Another benefit of REST is HATEOS (hypermedia as the engine of application state). This means that the hypermedia links that exist in a message describe the state of the system, and the links change as the state of the system changes. You can create a client that is late binded1 to the links in the message, which guide the client through what we are providing as a service. Consider how valuable this is if you have multiple independently deployed clients (websites, phone apps, desktop apps, etc) that consume the same service. If they understand the uniform interface and are late binded to the links in the message, the service can change how it "guides" the clients dynamically.

    Think of a message as the current state in a state machine, and a hypermedia link as instructions on how to bring the system to a new state. Clients are late binded to the transitions that exist in a message, which can change and be updated independently of the clients.

Conclusion

Every application has a set of requirements, and each architectural constraint induces both positive and negative properties on your system. Your goal is to create a set of properties that fulfils the requirements of your system.

Read Roy Fielding's dissertation for more information.

Footnotes:

1

Comment by Roy Fielding on late binding: http://intertwingly.net/blog/2008/03/23/Connecting

Author: Caleb Gossler

Last Modified: 2016-04-09 Sat 00:59